package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.CheckGroup;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface CheckGroupDao {
    public void add(CheckGroup checkGroup);

    public void setCheckGroupAndCheckItem(Map map);

    public Page<CheckGroup> selectByCondition(String queryString);

    @Select("select * from t_checkgroup where id = #{id}")
    CheckGroup findById(Integer id);

    @Select("select checkitem_id from t_checkgroup_checkitem where checkgroup_id = #{id}")
    List<Integer> findCheckItemIdsByCheckGroupId(Integer id);

    @Delete("delete from t_checkgroup_checkitem where checkgroup_id = #{id}")
    void deleteAssociation(Integer id);

    void edit(CheckGroup checkGroup);

    @Select("select * from t_checkgroup")
    List<CheckGroup> findByAll();

    @Select("select count(*) from t_checkgroup_checkitem where checkgroup_id = #{id}")
    Long selectCountByCheckGroupId(Integer id);

    @Delete("delete from t_checkgroup where id = #{id}")
    void delete(Integer id);

    //多表查询，根据套餐的id查询其中包含的检查项信息
    @Select("select * from t_checkgroup where id in (select checkgroup_id from t_setmeal_checkgroup where setmeal_id = #{id})")
    @Results({
            //封装该查询表的所对应的javabean对象封装属性
            @Result(column = "id", property = "id"),
            @Result(column = "code", property = "code"),
            @Result(column = "name", property = "name"),
            @Result(column = "helpCode", property = "helpCode"),
            @Result(column = "sex", property = "sex"),
            @Result(column = "remark", property = "remark"),
            @Result(column = "attention", property = "attention"),
            @Result(
            column = "id",//查询条件
            property = "checkItems",//setmeal中的属性
            javaType = List.class,//属性的类型   xml配置的时候注意：ofType(集合中所容纳的类型--》泛型)
            many = @Many(select = "com.itheima.dao.CheckItemDao.findCheckItemById")
    )
    })
    List<CheckGroup> findCheckGroupById(Integer id);
}
